//
//  XMJobSelectView.m
//  XMJJ_zml
//
//  Created by apple on 2025/5/19.
//

#import "XMJobSelectView.h"

@interface XMJobSelectView ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation XMJobSelectView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    self.backgroundColor = kColorHEX(0xf0f0f0);
    [self addSubview:self.navView];
    self.navTitleLabel.text = @"职业";
    
    UITableView *tbl = [[UITableView alloc] initWithFrame:CGRectMake(0, kNavagationBarH, self.width, KScaleWidth(200.0)) style:UITableViewStylePlain];
    tbl.delegate = self;
    tbl.dataSource = self;
    tbl.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    tbl.separatorColor = kColorHEX(0xf1f1f1);
    tbl.backgroundColor = kColorHEX(0xf0f0f0);
    if (@available(iOS 15.0, *)) {
        tbl.sectionHeaderTopPadding = 0;
    } else {
        tbl.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        // Fallback on earlier versions
    }
    [self addSubview:tbl];
    
    UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom font:KFontSize(17.0) frame:CGRectMake((self.width - KScaleWidth(320.0))/2, self.height - KScaleWidth(100.0) - KScaleWidth(44.0), KScaleWidth(320.0), KScaleWidth(44.0)) title:@"提交" titleColor:kColorHEX(0x333333)];
    [confirmBtn setGradientLayerWithLocations:@[@(0), @(1.0)] colors:@[(__bridge id)kColorHEX(0xFFD800).CGColor, (__bridge id)kColorHEX(0xFFE44E).CGColor] startPoint:CGPointMake(0.5, 0.37) endPoint:CGPointMake(0.03, 0.37)];
    [confirmBtn setCornerRadius:confirmBtn.height/2];
    [confirmBtn addTarget:self action:@selector(confirmAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:confirmBtn];
}

- (void)confirmAction:(UIButton *)button {
    
}

#pragma mark - Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return KScaleWidth(37.0);
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, KScaleWidth(37.0))];
    headView.backgroundColor = kColorHEX(0xf0f0f0);
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(16.0), 0, headView.width - KScaleWidth(16.0), headView.height) font:KFontSize(15.0) textColor:kColorHEX(0x666666)];
    titleLabel.text = @"个人职业";
    [headView addSubview:titleLabel];
    return headView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return KScaleWidth(50.0);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellName = @"XMJobSelectViewCellName";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellName];
        cell.textLabel.font = KFontSize(17.0);
        cell.textLabel.textColor = kColorHEX(0x333333);
        cell.detailTextLabel.font = KFontSize(15.0);
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.textLabel.text = @[@"实名认证", @"当前职业"][indexPath.row];
    if (indexPath.row == 0) {
        cell.detailTextLabel.text = @"去认证";
        cell.detailTextLabel.textColor = kColorHEX(0xDD4B39);
    }
    else {
        cell.detailTextLabel.text = @"选填";
        cell.detailTextLabel.textColor = kColorHEX(0x666666);
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    self.fucSelectBlock ? self.fucSelectBlock(indexPath.row) : nil;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
